/*
    api:"查询用户列表"
    name:"陈小洋"
    time：2021.2.13
* */
const User = require('../../../control/User/User')
const tools = require('../../../tools/public');
/**
 * @api {post} /user/SelUserList 5.查询用户列表
 * @apiGroup User
 *
 * @apiParam {Number} PageNumber 页码(默认为0)
 * @apiParam {Number} PageSize   分页大小(默认为100)
 * @apiParam {String} [NickName] 用户名字(支持模糊查询)
 * @apiParam {String} [sex] 用户性别
 * @apiParam {String} [birth] 用户生日
 * @apiParam {Number} [Register] 用户注册时间
 * @apiParam {Number} [RegionNumber] 用户生源地
 * @apiParam {String} [IsAbleUse] 用户是否可用
 * @apiParam {String} [Identity] 用户身份
 *
 *
 * @apiParamExample {json} Request-Example
 *{
 *
 *}
 * @apiSuccessExample  {json} Response-Example
 * {
 *   "code": 200,
 *   "msg": "查询成功！"
 *   }
 */
module.exports = async function (req, res, next) {
    let {PageNumber, PageSize} = req.body, result = null;
    PageNumber = PageNumber || 0
    PageSize = PageSize || 100

    try {
        // if (!PageNumber || !PageSize) return res.send(tools.ReturnData(204, '参数错误,请认真阅读接口文档！'));
        /******    处理参数为空的数据 不传给数据库    ******/
        let SelJson = {}
        let celue = ['sex', 'birth',
            'Register', 'RegionNumber', 'IsAbleUse', 'Identity']
        for (let i in celue) {
            req.body[celue[i]] ? SelJson[celue[i]] = req.body[celue[i]] : ""
        }
        /*****    处理参数的模糊查询    ******/
        let like_Json = {}
        let like_celue = ['NickName']
        for (let i in like_celue) {
            req.body[like_celue[i]] ? like_Json[like_celue[i]] = new RegExp(`${req.body[like_celue[i]]}`) : ""
        }

        result = await User.Sel(Number(PageNumber),Number(PageSize),Object.assign(SelJson, like_Json));
        let total = await User.Sel_Count(Object.assign(SelJson, like_Json))
        res.send(tools.ReturnData(200, '查询成功！', result, total));
    } catch (e) {
        console.log(e)
        return res.send(tools.ReturnData(500, '系统内部错误！'));
    }
};